<?php

include_once("common.php");

$title= "Upload";
$metaKey=null;
$metaDesc="Upload photos to homepage.";
$moreHtml=null;
$moreJava=null;

function republishPhoto($id){
	connectSelectTest("homePagePhotos");
	mysql_query("UPDATE `homePagePhotos` SET `dateUploaded`='".date("Y-m-d H:i:s", strtotime("now"))."' WHERE `id`='".$id."'");
	printf("<script type='text/javascript'>window.location = \"/upload.php\";</script>");
}

startPage($title, $metaKey, $metaDesc, $moreHtml, $moreJava, $title);

if ($_REQUEST['uploadCookie'] != "1024x768"){
	
	printf("<div class='autoBox' style='width:%s; padding:20px;'>\n", "100%");
	printf("<form style='margin-left:%s;'>\n", "39%");
	printf("<input type='password' value='%s' placeholder='password' name='pass' />\n", $_GET['pass']);
	printf("<input type='submit' value='¡log in!' />\n", $_GET['pass']);
	printf("</form>\n");
	printf("</div>\n");
	
	if ($_GET['pass'] == "chickens"){
		printf("<script type='text/javascript'>document.cookie = \"uploadCookie=1024x768\"</script>");
		printf("<script type='text/javascript'>window.location = \"/upload.php\";</script>");
	}
}
else{
	if ($_GET['repub']){
		republishPhoto($_GET['repub']);
	}
	
	$warning = "¡¡IMPORTANTE!! Upload files with a 1024x768 aspect ratio, also for speeds sake try to keep files under 70 kilobytes.";
	
	connectSelectTest("homePagePhotos");
	$currentResult = mysql_query("SELECT * FROM `homePagePhotos` ORDER BY `dateUploaded` DESC");
	$currentList = "<ol>\n";
	while ($currentImages = mysql_fetch_array($currentResult)){
		$currentList .= "<li>\n<p>".$currentImages['title']."</p><img style='width:100px;' src='".$currentImages['file']."' /><br><a id='onBlue' href='?repub=".$currentImages['id']."'>re-publish</a>\n</li>\n";
	}
	$currentList .= "</ol>\n";
	$currentlyExisting = "<div style='width:100%; height:500px; overflow:scroll;'>\n".$currentList."</div>\n";
	
	$form = "<h4>New Image...</h4>
			<form style='margin-left:5%;' action='uploadPhoto.php' method='post'enctype='multipart/form-data'>
			<input type='text' name='title' placeholder='photo title'>
			<input type='file' name='pic'>
			<input type='hidden' name='dateUploaded' value='".date("Y-m-d H:i:s", strtotime("now"))."'><br><br>
			<input type='submit' name='submit' value='¡upload!'>
			</form>";
	
	$first = mainBox($warning, "autoBox", "0px");
	$second = verseBox("0px", $currentlyExisting, "currently in the database...<br><font size='1%'>first 8 will appear on home page.</font>", "linkBox");
	$third = mainBox($form, "autoBox", "-500px");
	$fourth = "<div style='height:5px; width:250px;'></div>";
	
	printPageTable($first, $second, $third, $fourth);
}
endPage();